﻿namespace Bll.Systems
{
    using IDal.Systems;
    using Model.Systems;
    using System;
    using System.Data;
    using WinFormSession;
    using DALFactory;
    public class IdocumentCodeBll
    {
        private static readonly IIdocumentCode dal = DataAccess.CreateIdocumentCode();

        public static void Add(IdocumentCodeEnt model)
        {
            dal.Add(model);
        }

        public static void Delete(int ID)
        {
            dal.Delete(ID);
        }

        public static DataTable GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        public static int GetMaxId(string swhere)
        {
            return dal.GetMaxId(swhere);
        }

        public static string GetMaxValue(string codeRefName)
        {
            string str = "";
            IdocumentCodeEnt model = dal.GetModel(codeRefName);
            if (model == null)
            {
                return str;
            }
            string str2 = dal.GetMaxValue(codeRefName).ToString();
            if (str2.Length == 1)
            {
                str2 = "000" + str2;
            }
            if (str2.Length == 2)
            {
                str2 = "00" + str2;
            }
            if (str2.Length == 3)
            {
                str2 = "0" + str2;
            }
            UserEnt ent2 = (UserEnt) WinformSession.GetSession()["user"];
            string str3 = ent2.ChainNum.ToString();
            if (str3.Length == 1)
            {
                str3 = "0" + str3;
            }
            return (DateTime.Now.ToString("yyyyMMdd") + str3 + model.CodeNum + str2);
        }

        public static string GetMaxValue2(string codeRefName)
        {
            string str = "";
            if (dal.GetModel(codeRefName) != null)
            {
                str = dal.GetMaxValue(codeRefName).ToString();
            }
            return str;
        }

        public static IdocumentCodeEnt GetModel(int ID)
        {
            return dal.GetModel(ID);
        }

        public static DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetPageList(PageSize, PageIndex, strWhere);
        }

        public static void Update(IdocumentCodeEnt model)
        {
            dal.Update(model);
        }

        public static void UpdateMaxValue(string codeRefName)
        {
            dal.UpdateMaxValue(codeRefName);
        }
    }
}

